package com.doodle.common.utils;

public class SfbFace {

	private int[] LEFT_EYE_INDICES = { 12, 13, 14, 15, 16, 17 };
    private int[] RIGHT_EYE_INDICES = { 18, 19, 20, 21, 22, 23 };
    private int[] MOUTH_INDICES = { 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
            43, 62, 63, 64, 65, 66, 67 };

    // 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43
    public static final int[] MOUTH_CONTOUR = new int[] { 32, 33, 34, 35, 36,
            37, 38, 39, 40, 41, 42, 43 };
    public static final int[] MOUTH_LINE_1 = new int[] { 62, 63, 64 };
    public static final int[] MOUTH_LINE_2 = new int[] { 65, 66, 67 };

    /**
     * The face unique identifier. Used to identify the faces between successive
     * calls to ::Analyze and ::Process functions.
     */
    private int id;

    /**
     * Bounding box surrounding the face area.
     */
    private GTRect rcFace;

    /**
     * Left eye center
     */
    private GTPoint ptLeftEye;

    /**
     * Right eye center
     */
    private GTPoint ptRightEye;

    /**
     * Mouth center
     */
    private GTPoint ptMouth;

    /**
     * Face feature points
     */
    public GTPoint[] landmarks;

    /**
     * Bit field value containing one or more SFB_FEATURE values OR-ed.
     * Specifies the features that can be applied on the face.
     */
    private int faceFeatures;

    /**
     * The SFB configuration settings that will be applied on this face.
     */

    public SfbFace() {
        this.rcFace = new GTRect();
        this.ptLeftEye = new GTPoint();
        this.ptRightEye = new GTPoint();
        this.ptMouth = new GTPoint();
        this.landmarks = new GTPoint[250];
        for (int i = 0; i < landmarks.length; i++)
            landmarks[i] = new GTPoint();
    }

    public int getId() {
        return id;
    }

    public GTRect getFaceRectangle()  {
        return rcFace;
    }

    public GTPoint getLeftEye() {
        return ptLeftEye;
    }

    public GTPoint getRightEye() {
        return ptRightEye;
    }

    public GTPoint getMouth() {
        return ptMouth;
    }

    public void setLeftEye(GTPoint p) {
        ptLeftEye = p;
    }

    public void setRightEye(GTPoint p) {
        ptRightEye = p;
    }

    public void setMouth(GTPoint p) {
        ptMouth = p;
    }

    public int getFaceFeatures() {
        return faceFeatures;
    }

    public GTPoint[] getLandmarks() {
        return this.landmarks;
    }

    public void setLandMarks(GTPoint[] landmarks) {
        this.landmarks = landmarks;
    }

    private GTPoint[] mleftEye;

    public GTPoint[] getLeftEyeLandmarks() {
        if (mleftEye != null) {
            return mleftEye;
        }
        mleftEye = new GTPoint[LEFT_EYE_INDICES.length];
        for (int i = 0; i < LEFT_EYE_INDICES.length; ++i) {
            mleftEye[i] = landmarks[LEFT_EYE_INDICES[i]];
        }
        return mleftEye;
    }

    private GTPoint[] mRightEye;

    public GTPoint[] getRightEyeLandmarks() {
        if (mRightEye != null) {
            return mRightEye;
        }
        mRightEye = new GTPoint[RIGHT_EYE_INDICES.length];
        for (int i = 0; i < RIGHT_EYE_INDICES.length; ++i) {
            mRightEye[i] = landmarks[RIGHT_EYE_INDICES[i]];
        }
        return mRightEye;
    }

    private GTPoint[] mMouth;

    public GTPoint[] getMouthLandmarks() {
        if (mMouth != null) {
            return mMouth;
        }
        mMouth = new GTPoint[MOUTH_INDICES.length];
        for (int i = 0; i < MOUTH_INDICES.length; ++i) {
            mMouth[i] = landmarks[MOUTH_INDICES[i]];
        }
        return mMouth;
    }

    private GTPoint[] mMouthOutsideContour;

    public GTPoint[] getMouthOutsideContour() {
        if (mMouthOutsideContour != null) {
            return mMouthOutsideContour;
        }
        mMouthOutsideContour = new GTPoint[MOUTH_CONTOUR.length];
        for (int i = 0; i < MOUTH_CONTOUR.length; ++i) {
            mMouthOutsideContour[i] = landmarks[MOUTH_CONTOUR[i]];
        }
        return mMouthOutsideContour;
    }

    private GTPoint[] mMouthLine1;

    public GTPoint[] getMouthLine1() {
        if (mMouthLine1 != null) {
            return mMouthLine1;
        }
        mMouthLine1 = new GTPoint[MOUTH_LINE_1.length];
        for (int i = 0; i < MOUTH_LINE_1.length; ++i) {
            mMouthLine1[i] = landmarks[MOUTH_LINE_1[i]];
        }
        return mMouthLine1;
    }

    private GTPoint[] mMouthLine2;

    public GTPoint[] getMouthLine2() {
        if (mMouthLine2 != null) {
            return mMouthLine2;
        }

        mMouthLine2 = new GTPoint[MOUTH_LINE_2.length];
        for (int i = 0; i < MOUTH_LINE_2.length; ++i) {
            mMouthLine2[i] = landmarks[MOUTH_LINE_2[i]];
        }
        return mMouthLine1;
    }

    public boolean isFeatureEnabled(int featureId) {
        return (faceFeatures & (1 << featureId)) != 0;
    }
}
